﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using TGB.Core.Infrastructure;
using TGBTech.Core.Models.Models.ChungTu;

namespace TGBTech.WebAdmin.Controllers
{
    public class CTChungTuXuatsController : Controller
    {
        private TGBTechDb db = new TGBTechDb();

        // GET: CTChungTuXuats
        public ActionResult Index()
        {
            var cTChungTuXuats = db.CTChungTuXuats.Include(c => c.ChungTuXuat).Include(c => c.CTHangHoa);
            return View(cTChungTuXuats.ToList());
        }

        // GET: CTChungTuXuats/Details/5
        public ActionResult Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            CTChungTuXuat cTChungTuXuat = db.CTChungTuXuats.Find(id);
            if (cTChungTuXuat == null)
            {
                return HttpNotFound();
            }
            return View(cTChungTuXuat);
        }

        // GET: CTChungTuXuats/Create
        public ActionResult Create()
        {
            ViewBag.ChungTuXuatId = new SelectList(db.ChungTuXuats, "Id", "SoCT");
            ViewBag.CTHangHoaId = new SelectList(db.ChiTietHangHoa, "Id", "HangHoaId");
            return View();
        }

        // POST: CTChungTuXuats/Create
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "Id,ChungTuXuatId,SoHieu,SoHoaDon,NgayHoaDon,CTHangHoaId,SoLuong,DonGia,VAT")] CTChungTuXuat cTChungTuXuat)
        {
            if (ModelState.IsValid)
            {
                db.CTChungTuXuats.Add(cTChungTuXuat);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.ChungTuXuatId = new SelectList(db.ChungTuXuats, "Id", "SoCT", cTChungTuXuat.ChungTuXuatId);
            ViewBag.CTHangHoaId = new SelectList(db.ChiTietHangHoa, "Id", "HangHoaId", cTChungTuXuat.CTHangHoaId);
            return View(cTChungTuXuat);
        }

        // GET: CTChungTuXuats/Edit/5
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            CTChungTuXuat cTChungTuXuat = db.CTChungTuXuats.Find(id);
            if (cTChungTuXuat == null)
            {
                return HttpNotFound();
            }
            ViewBag.ChungTuXuatId = new SelectList(db.ChungTuXuats, "Id", "SoCT", cTChungTuXuat.ChungTuXuatId);
            ViewBag.CTHangHoaId = new SelectList(db.ChiTietHangHoa, "Id", "HangHoaId", cTChungTuXuat.CTHangHoaId);
            return View(cTChungTuXuat);
        }

        // POST: CTChungTuXuats/Edit/5
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit([Bind(Include = "Id,ChungTuXuatId,SoHieu,SoHoaDon,NgayHoaDon,CTHangHoaId,SoLuong,DonGia,VAT")] CTChungTuXuat cTChungTuXuat)
        {
            if (ModelState.IsValid)
            {
                db.Entry(cTChungTuXuat).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.ChungTuXuatId = new SelectList(db.ChungTuXuats, "Id", "SoCT", cTChungTuXuat.ChungTuXuatId);
            ViewBag.CTHangHoaId = new SelectList(db.ChiTietHangHoa, "Id", "HangHoaId", cTChungTuXuat.CTHangHoaId);
            return View(cTChungTuXuat);
        }

        // GET: CTChungTuXuats/Delete/5
        public ActionResult Delete(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            CTChungTuXuat cTChungTuXuat = db.CTChungTuXuats.Find(id);
            if (cTChungTuXuat == null)
            {
                return HttpNotFound();
            }
            return View(cTChungTuXuat);
        }

        // POST: CTChungTuXuats/Delete/5
        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            CTChungTuXuat cTChungTuXuat = db.CTChungTuXuats.Find(id);
            db.CTChungTuXuats.Remove(cTChungTuXuat);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}
